package com.syni.mdd.sjb.common.datatreaure.controller.protect.pay;

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckUserIdentity;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.pay.PayRqVo;
import com.syni.mdd.sjb.common.datatreaure.service.WechatPayService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/wechatPay")
@Log4j2
public class WechatPayController {

    @Autowired
    WechatPayService wechatPayService;

    @PostMapping("prepay")
    @ApiOperation(value = "微信统一下单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId",value = "订单ID"),
            @ApiImplicitParam(name = "orderNo",value = "订单NO")
    })
    @CheckUserIdentity
    Map<String,Object> prepay(@RequestBody @Validated PayRqVo payRqVo){
        return wechatPayService.prepay(payRqVo);

    }

    /**
     * 支付结果回调
     */
    @PostMapping("/AppWechatPayNotify")
    public synchronized void AppWechatPayNotify() {
        try{
            wechatPayService.appWechatPayNotify();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
